package cn.cnsy123.shorturls.api.controller.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.cnsy123.shorturls.api.controller.param.ShortAddrInsertParam;
import cn.cnsy123.shorturls.api.controller.param.ShortAddrQueryParam;
import cn.cnsy123.shorturls.api.controller.param.ShortAddrUpdateParam;
import cn.cnsy123.shorturls.api.controller.vo.ShortUrlQueryResult;
import cn.cnsy123.shorturls.api.controller.vo.ShortUrlSaveResult;
import cn.cnsy123.shorturls.business.service.ShortUrlAddrService;

@Controller
@RequestMapping("/shortAddress")
public class ShortAddressController {
    
    @Autowired
    private ShortUrlAddrService shortUrlAddrService; 
    
    @RequestMapping(value = "/get",method = RequestMethod.GET)
    @ResponseBody
    public ShortUrlQueryResult queryShortAddress(ShortAddrQueryParam shortAddrQueryParam) {
        try {
            return shortUrlAddrService.queryShortAddress(shortAddrQueryParam);
        } catch (Exception e) {
            return new ShortUrlQueryResult(Integer.valueOf(500),"查询短地址信息列表异常");
        }
    }
    
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public ShortUrlSaveResult updateShortAddressInfo(ShortAddrUpdateParam shortAddrUpdateParam) {
        try {
            return shortUrlAddrService.updateShortAddressInfo(shortAddrUpdateParam);
        } catch (Exception e) {
            return new ShortUrlSaveResult(Integer.valueOf(500),"更新短地址状态异常");
        }
    }
    
    @RequestMapping(value = "/insert",method = RequestMethod.PUT)
    @ResponseBody
    public ShortUrlSaveResult insertShortAddressInfo(ShortAddrInsertParam shortAddrInsertParam) {
        try {
            return shortUrlAddrService.saveShortUrlAddrInfo(shortAddrInsertParam);
        } catch (Exception e) {
            return new ShortUrlSaveResult(500, "生成短地址信息异常");
        }
    }
    

}
